package com.itic.mall.system.orders.orderJD.service;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.mall.system.inter.orders.orderJD.persistence.dao.OrderJDDao;
import com.itic.mall.system.inter.orders.orderJD.persistence.model.OrderJD;
import com.itic.mall.system.inter.orders.orderJD.persistence.model.OrderJDExample;
import com.itic.mall.system.inter.orders.orderJD.persistence.model.OrderJDExample.Criteria;
import com.itic.mall.system.pay.userlog.service.PayUserlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class OrderJDService
     extends CrudService<OrderJDDao,OrderJD,OrderJDExample> {
    @Autowired
    private OrderJDDao orderJDDao;
    @Autowired
    private PayUserlogService payUserlogService;

    public OrderJD getOrderJDByOrderNum(String orderNum) {
    	OrderJDExample example = new OrderJDExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andOrderNumEqualTo(orderNum);
    	List<OrderJD> orderJDs = this.list(example);
    	if(orderJDs.isEmpty())
    		return null;
    	return orderJDs.get(0);
    }
    /**
     * 获取JD计算过累计成功的订单
     * @param userId
     * @return
     */
    public List<OrderJD> findUserJiSuanSuccessOrderJD(String userId){
    	OrderJDExample example = new OrderJDExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andUserIdEqualTo(userId);
    	criteria.andOrderStatusEqualTo("L1");
    	List<OrderJD> orderJDs = this.list(example);
    	return orderJDs;
    }
  
}